import Main from '@/views/Main.vue';
import Cookies from 'js-cookie';
import meunUtils from '../tool/MenuUtils';
// 必填，且不能和其父路由的name不一致（与其他任何路由的name值都不能一致）
// 不作为Main组件的子页面展示的页面单独写，如下
export const loginRouter = {
	path: '/login',
	name: 'login',
	meta: {
		title: 'Login - 登录'
	},
	component: resolve => {
		require(['@/views/login.vue'], resolve);
	}
};
export const invalidPage = {
	path: '/invalidPage',
	name: 'invalidPage',
	meta: {
		title: '账号过期'
	},
	component: resolve => {
		require(['@/views/invalidPage.vue'], resolve);
	}
};
export const page404 = {
	path: '*',
	name: 'error-404',
	meta: {
		title: '404-页面不存在'
	},
	component: resolve => {
		require(['@/views/error-page/404.vue'], resolve);
	}
};
export const page403 = {
	path: '/403',
	meta: {
		title: '403-权限不足'
	},
	name: 'error-403',
	component: resolve => {
		require(['@/views/error-page/403.vue'], resolve);
	}
};
export const page500 = {
	path: '/500',
	meta: {
		title: '500-服务端错误'
	},
	name: 'error-500',
	component: resolve => {
		require(['@/views/error-page/500.vue'], resolve);
	}
};
export const locking = {
	path: '/locking',
	name: 'locking',
	component: resolve => {
		require([
			'@/views/main-components/lockscreen/components/locking-page.vue'
		], resolve);
	}
};

// 作为Main组件的子页面展示但是不在左侧菜单显示的路由写在otherRouter里
export const otherRouter = {
	path: '/',
	name: 'otherRouter',
	redirect: '/home',
	component: Main,
	children: [
		{
			path: '/noticeDetail',
			title: '通知详情',
			name: 'noticeDetail',
			allPath: [
				{path: '/notice/notice-index', title: '通知列表'},
				{title: '通知详情'}
			],
			component: resolve => {
				require(['@/views/notice/notice-detail.vue'], resolve);
			}
		},
        {
            path: '/shareDetail',
            title: '分享详情',
            name: 'shareDetail',
            allPath: [
                {path: '/share/share-index', title: '分享管理'},
                {title: '分享详情'}
            ],
            component: resolve => {
                require(['@/views/shareManage/share-detail.vue'], resolve);
            }
        },
        {
            path: '/videoDetail',
            title: '视频详情',
            name: 'videoDetail',
            allPath: [
                {path: '/video/video-index', title: '视频管理'},
                {title: '视频详情'}
            ],
            component: resolve => {
                require(['@/views/video/video-detail.vue'], resolve);
            }
        },
        {
            path: '/briefDetail',
            title: '通报详情',
            name: 'briefDetail',
            allPath: [
                {path: '/brief/brief-index', title: '通报管理'},
                {title: '通报详情'}
            ],
            component: resolve => {
                require(['@/views/brief/brief-detail.vue'], resolve);
            }
        },
        {
            path: '/companyFileDetail',
            title: '文件详情',
            name: 'companyFileDetail',
            allPath: [
                {path: '/companyFile/companyFile-index', title: '公司制度文件'},
                {title: '文件详情'}
            ],
            component: resolve => {
                require(['@/views/companyFile/companyFile-detail.vue'], resolve);
            }
        }

	]
};

// 作为Main组件的子页面展示并且在左侧菜单显示的路由写在appRouter里
// 这里是权限控制，这次没有权限控制，所以注释掉
export let appRouter = [];
const _sid = Cookies.get('flc_sid');
let _menuInfo = window.localStorage.getItem('flc_plamenuInfo');
if (_sid && _menuInfo !== undefined) {
	_menuInfo = JSON.parse(_menuInfo);
	let _router = meunUtils(_menuInfo);
	appRouter = _router;
}

export const routers = [
	loginRouter,
	otherRouter,
	...appRouter,
	locking,
	page500,
	page403,
	page404,
	invalidPage
];
